package com.itheima.stock.Thread;

public class Yield {
    public static void main(String[] args) {
        MyThread1 t1 = new MyThread1();
        MyThread2 t2 = new MyThread2();
        t1.setName("女神");
        t2.setName("男神");
        t1.start();
        t2.start();

    }


    /**
     *  public static void yield() 线程礼让 （每执行一次退出线程重新抢夺）
     */
    static class MyThread1 extends Thread{
        @Override
        public void run(){
            for (int i = 0; i < 10; i++) {
                System.out.println(getName()+i);
                Thread.yield();
            }

        }
    }


    static class MyThread2 extends Thread{
        @Override
        public void run(){
            for (int i = 0; i < 10; i++) {
                System.out.println(getName()+i);
                Thread.yield();
            }
        }
    }
}
